package com.shuai.jit.utils;

import java.util.Random;

public class RandomString {

    public static String getRandomString(int length){
        //定义一个字符串（A-Z，a-z，0-9）即62位；
        String str="zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        //由Random生成随机数
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        //长度为几就循环几次
        for(int i=0; i<length; ++i){
            //产生0-61的数字
            int number=random.nextInt(62);
            //将产生的数字通过length次承载到sb中
            sb.append(str.charAt(number));
        }
        //将承载的字符转换成字符串
        return sb.toString();
    }

    public static String getRandomChineseString(int length){
        //定义一个字符串（A-Z，a-z，0-9）即62位；
        String str="中国牛逼嘿嘿啦李王张刘陈杨赵黄周吴徐孙胡朱高林何郭马罗\n" +
                "梁宋郑谢韩唐冯于董萧程曹袁邓许傅沈曾彭吕\n" +
                "苏卢蒋蔡贾丁魏薛叶阎余潘杜戴夏钟汪田任姜\n" +
                "范方石姚谭廖邹熊金陆郝孔白崔康毛邱秦江史\n" +
                "顾侯邵孟龙万段雷钱汤尹黎易常武乔贺赖龚文\n" +
                "庞樊兰殷施陶洪翟安颜倪严牛温芦季俞章鲁葛\n" +
                "伍韦申尤毕聂丛焦向柳邢骆岳齐尚梅莫庄辛管\n" +
                "祝左涂谷祁时舒耿牟卜路詹关苗凌费纪靳盛童\n" +
                "欧甄项曲成游阳裴席卫查屈鲍位覃霍翁隋植甘\n" +
                "景蒲单包司柏宁柯阮桂闵欧阳 解强柴华车冉房边\n" +
                "辜吉饶刁瞿戚丘古米池滕晋苑邬臧畅宫来缪苟\n" +
                "全褚廉简娄盖符奚木穆党燕郎邸冀谈姬屠连郜\n" +
                "晏栾郁商蒙计喻揭窦迟宇敖糜鄢冷卓花仇艾蓝都巩稽井练仲乐虞卞封竺冼原官衣楚佟栗匡宗zxcvbnmlkjhgfdsaqwertyuiopQWERTYUIOPASDFGHJKLZXCVBNM1234567890";
        //由Random生成随机数
        Random random=new Random();
        StringBuffer sb=new StringBuffer();
        //长度为几就循环几次
        for(int i=0; i<length; ++i){
            //产生0-61的数字
            int number=random.nextInt(62);
            //将产生的数字通过length次承载到sb中
            sb.append(str.charAt(number));
        }
        //将承载的字符转换成字符串
        return sb.toString();
    }

    public static String getRandomNumber(Integer length){
        String sources = "0123456789"; // 加上一些字母，就可以生成pc站的验证码了
        Random rand = new Random();
        StringBuffer flag = new StringBuffer();
        for (int j = 0; j < length; j++)
        {
            flag.append(sources.charAt(rand.nextInt(9)) + "");
        }
        return  flag.toString();
    }
}
